#!/usr/bin/env python
import sys
import helper
import class_set
from sets import Set

class FeedRecommendationReducer(helper.ReducerHelper):
    def processor(self, key, lst):
        list_type_like = Set()
        list_type_comment = Set()
        list_type_author = Set()
        for e in lst:
            left, right = self.split(e)
            if left is not None:
                recom_tag = class_set.RecomTag('')
                recom_tag.init(right)
                if recom_tag.isType('like'):
                    list_type_like.add(left)
                else:
                    list_type_comment.add(left)
            else:
                list_type_author.add(e)
            
        like_tag = class_set.RecomTag('like')
        comment_tag = class_set.RecomTag('comment')
        for ul in list_type_like:
            for ur in list_type_author:
                if ul != ur:
                    self.allocator(self.join(ul, ur), like_tag)

        for ul in list_type_comment:
            for ur in list_type_author:
                if ul != ur:
                    self.allocator(self.join(ul, ur), comment_tag) 

def main():
    fr = FeedRecommendationReducer()
    fr.reducer()

if __name__ == '__main__':
    main()

